package mo.leetcode_top;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class L139 {

    public boolean wordBreak(String s, List<String> wordDict) {
        boolean[] dp = new boolean[s.length()+1];
        dp[0] = true;
        Set<String> wordSet = new HashSet<>(wordDict);
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j <= i; j++) {
                if (dp[j] && wordSet.contains(s.substring(j, i+1))) {
                    dp[i+1] = true;
                    break;
                }
            }
        }
        return dp[s.length()];
    }

    public static void main(String[] args) {
        L139 test = new L139();
        System.out.println(test.wordBreak("a", Arrays.asList("a")));
    }

}
